package com.echo.model.common;


import com.echo.model.context.LoginUser;

import javax.servlet.http.HttpServletRequest;

/**
 * @author chentl
 * @date 2018/8/29 15:09
 */
public class RequestHolder {

    private static final ThreadLocal<LoginUser> userHolder = new ThreadLocal<>();

    private static final ThreadLocal<HttpServletRequest> requestHolder = new ThreadLocal<>();

    public static void add(LoginUser loginUser) {
        userHolder.set(loginUser);
    }

    public static void add(HttpServletRequest request) {
        requestHolder.set(request);
    }

    public static LoginUser getCurrentUser() {
        return userHolder.get();
    }

    public static HttpServletRequest getCurrentRequest() {
        return requestHolder.get();
    }

    public static void remove() {
        userHolder.remove();
        requestHolder.remove();
    }

}